package com.sharemarking.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.sharemarking.system.entity.Menu;
import com.sharemarking.system.service.impl.MybatisCacheFactoryEhcacheImpl;

@CacheNamespace(implementation=MybatisCacheFactoryEhcacheImpl.class)
public interface MenuMapper {
	@Select("SELECT * FROM sys_menu ORDER BY sort")
	List<Menu> getSortedMenu();
	@Insert("INSERT INTO sys_menu(icon,name,sort,url,target,permission_id,parent_id) "
			+ "VALUES (#{icon},#{name},#{sort},#{url},#{target},#{permissionId},#{parentId}) ")
	@Options(useGeneratedKeys=true, keyProperty="id",keyColumn = "id")
	void insert(Menu menu);
	@Select("SELECT * FROM sys_menu WHERE id=#{id}")
	Menu get(int id);
	@Update("UPDATE sys_menu "
			+ "SET icon=#{icon},name=#{name},sort=#{sort},url=#{url},target=#{target},permission_id=#{permissionId} "
			+ "WHERE id=#{id} ")
	void updateInfo(Menu menu);
	@Delete("DELETE FROM sys_menu WHERE id=#{id}")
	void delete(int id);
	@Delete("DELETE FROM sys_menu WHERE parent_id=#{parentId}")
	void deleteChild(int parentId);
}
